#include "MySqlQueryModel.h"

MySqlQueryModel::MySqlQueryModel(QObject *parent) :
    QSqlQueryModel(parent)
{
    bOk = false;
}

QVariant    MySqlQueryModel::data(const QModelIndex &item, int role) const
{
//    int col = item.column();
    int row = item.row();
    switch ( role )
    {
//    QString times = "";
    /*
    case Qt::DisplayRole :
        if (col == 1)
        {
            QColor color;
            QString time = QSqlQueryModel::data(item, role).toString();
            QTime   t = QTime::fromString(time, "HH:mm");
            qDebug() << "time = " << time << " | " << "t :" << t;
            if (t < QTime::currentTime())
//            {
//                mensaje();
                qDebug() << "ok";
//            }
            return time.arg(color.red());
        }
        break;
        */
    case Qt::TextAlignmentRole :
        return Qt::AlignHCenter + Qt::AlignVCenter;
        break;
    case Qt::BackgroundRole :
    {
//        QString Time = QSqlQueryModel::data(item, role).toString();            qDebug() << "Time = " << Time;
        if (row == (rowCount() - 1)/* && col == 1*/)
        {
//            QDateTime time = QSqlQueryModel::data(item, role).toDateTime();
//            qDebug() << "time = " << time;
//            if (QDateTime::currentDateTime() < time)
//            {
                QBrush redBackground("#ff4d4d");
                return redBackground;
//            }
        }
        break;
    }
    }
//    qDebug() << QString("row %1, col %2, rol %3").arg(row).arg(col).arg(role) << QSqlQueryModel::data(item, role);
    return  QSqlQueryModel::data(item, role);
}

void MySqlQueryModel::mensaje()
{
    bOk = true;
}
